<template>
  <div class="page-header-index-wide">
    <a-row :gutter="24">
      <a-col :sm="24" :md="12" :xl="6" :style="{ marginBottom: '24px' }">
        <chart-card :loading="loading" title="产品销售额（元）" :total="ord_sum">
          <a-tooltip title="全部销售额" slot="产品销售额">
            <a-icon type="info-circle-o" />
          </a-tooltip>
        </chart-card>
      </a-col>
      <a-col :sm="24" :md="12" :xl="6" :style="{ marginBottom: '24px' }">
        <chart-card :loading="loading" title="产品订单量（单）" :total="ord_num">
          <a-tooltip title="指标说明" slot="产品订单量">
            <a-icon type="info-circle-o" />
          </a-tooltip>
          <div>
<!--            <mini-area />-->
          </div>
<!--          <template slot="footer">日订单量<span> {{ '1234' | NumberFormat }}</span></template>-->
        </chart-card>
      </a-col>
      <a-col :sm="24" :md="12" :xl="6" :style="{ marginBottom: '24px' }">
        <chart-card :loading="loading" title="本年度故障信息（条）" :total="fau_sum">
          <a-tooltip title="指标说明" slot="本年度故障信息">
            <a-icon type="info-circle-o" />
          </a-tooltip>
          <div>
<!--            <mini-bar :height="40" />-->
          </div>
<!--          <template slot="footer">转化率 <span>60%</span></template>-->
        </chart-card>
      </a-col>

      <a-col :sm="24" :md="12" :xl="6" :style="{ marginBottom: '24px' }">
        <chart-card :loading="loading" title="订单退款率" :total="ord_tuikuan">
          <a-tooltip title="指标说明" slot="订单退款率">
            <a-icon type="info-circle-o" />
          </a-tooltip>
          <div>
<!--              <mini-progress color="rgb(19, 194, 194)" :target="100" :percentage="78" :height="8" />-->
          </div>
        </chart-card>
      </a-col>
    </a-row>

    <a-card>
      <a-tabs default-active-key="1" size="large" :tab-bar-style="{marginBottom: '24px', paddingLeft: '16px'}">
        <a-tab-pane loading="true" tab="产品订单量及顾客分布地区统计" key="1">
      <div style="width: 100%">
<!--        <div style="width: 65%;float: left"><bar title="产品订单量排行" :dataSource="barData"/></div>-->
        <div style="width: 65%;float: left"><bar title="产品订单量排行" :dataSource="barData"/></div>
        <div style="width: 35%;float: left"><pie title="地区分布" :dataSource="pieData" height="400"/></div>
      </div>
        </a-tab-pane>

        <a-tab-pane loading="true" tab="本年度故障信息统计" key="2">
          <div style="width: 100%">
            <area-chart-ty title="2021年每月份故障信息" :dataSource="areaData"  height="450"/>
          </div>
        </a-tab-pane>
      </a-tabs>

    </a-card>

    <a-card style="margin-top: 20px">
      <a-tabs default-active-key="1" size="large" :tab-bar-style="{marginBottom: '24px', paddingLeft: '16px'}">
        <a-tab-pane loading="true" tab="员工正常签到统计" key="1">
          <div style="width: 100%">
            <line-chart-multid :dataSource="line_data" :height="450"></line-chart-multid>
          </div>
        </a-tab-pane>

        <a-tab-pane loading="true" tab="员工未签到统计" key="2">
          <div style="width: 100%">
            <line-chart-multid :dataSource="line_data2" :height="450"></line-chart-multid>
          </div>
        </a-tab-pane>

        <a-tab-pane loading="true" tab="员工请假统计" key="3">
          <div style="width: 100%">
            <line-chart-multid :dataSource="line_data3" :height="450"></line-chart-multid>
          </div>
        </a-tab-pane>

        <a-tab-pane loading="true" tab="员工缺勤统计" key="4">
          <div style="width: 100%">
            <line-chart-multid :dataSource="line_data4" :height="450"></line-chart-multid>
          </div>
        </a-tab-pane>
      </a-tabs>

    </a-card>






  </div>
</template>

<script>

  import ChartCard from '@/components/ChartCard'
  import ACol from "ant-design-vue/es/grid/Col"
  import ATooltip from "ant-design-vue/es/tooltip/Tooltip"
  import MiniArea from '@/components/chart/MiniArea'
  import MiniBar from '@/components/chart/MiniBar'
  import MiniProgress from '@/components/chart/MiniProgress'
  import RankList from '@/components/chart/RankList'
  import Bar from '@/components/chart/Bar'
  import LineChartMultid from '@/components/chart/LineChartMultid'
  import HeadInfo from '@/components/tools/HeadInfo.vue'

  import Trend from '@/components/Trend'
  import { getLoginfo,getVisitInfo } from '@/api/api'

  import { httpAction, getAction } from '@/api/manage'
  import Pie from '../../components/chart/Pie'
  import BarAndLine from '../../components/chart/BarAndLine'
  import AreaChartTy from '../../components/chart/AreaChartTy'
  import BarMultid from '../../components/chart/BarMultid'


  const barData = []

  const barData2 = []

  const pieData = []

  const areaData = []

  const line_data = [  //empMm/empSignin/empNosign/empLeave/empAbsent
  ]
  const line_data2 = []
  const line_data3 = []
  const line_data4 = []




  export default {
    name: "IndexChart",
    components: {
      BarMultid,
      AreaChartTy,
      BarAndLine,
      Pie,
      ATooltip,
      ACol,
      ChartCard,
      MiniArea,
      MiniBar,
      MiniProgress,
      RankList,
      Bar,
      Trend,
      LineChartMultid,
      HeadInfo
    },
    data() {
      return {
        loading: true,
        ord_num:0,
        ord_sum:0,
        fau_sum:0,
        ord_tuikuan:0,
        center: null,
        barData,
        pieData,
        barData2,
        areaData,
        line_data,
        line_data2,
        line_data3,
        line_data4,
        loginfo:{},
        visitFields:['ip','visit'],
        visitInfo:[],
        indicator: <a-icon type="loading" style="font-size: 24px" spin />,
      }
    },
    created() {
      setTimeout(() => {
        this.loading = !this.loading
      }, 1000)
      this.initLogInfo();
    },
    methods: {
      initLogInfo () {
        getLoginfo(null).then((res)=>{
          if(res.success){
            Object.keys(res.result).forEach(key=>{
              res.result[key] =res.result[key]+""
            })
            this.loginfo = res.result;
          }
        })
        getVisitInfo().then(res=>{
          if(res.success){
             this.visitInfo = res.result;
           }
         })
          //在IndexData控制器里读取视图数据
          //发起一个网络访问

          //产品销售统计
          const that = this;
          getAction("machineShop/index/get",{}).then((res)=>{
              if(res.success){
                  console.log(res)
                  // that.pro_no = res.result[0].nums//取其中某一组数据1
                  //总数求和
                  var sum = 0;
                  for (let i = 0; i <res.result.length ; i++) {
                      sum +=res.result[i].nums;
                  }
                  that.ord_num = sum ;

                  for (let i = 0; i <res.result.length ; i++) {
                     barData.push({
                         x:res.result[i].proName,
                         y:res.result[i].nums
                     })
                  }
                  //that.$message.success(res.message);
                 // that.$emit('ok');
              }else{
                  //that.$message.warning(res.message);
              }
          }),
            //产品销售额
            getAction("machineShop/index/get1",{}).then((res)=>{
              if(res.success){

                console.log(res)
                // that.pro_no = res.result[0].nums//取其中某一组数据1
                var sum = 0;
                for (let i = 0; i <res.result.length ; i++) {
                  sum +=res.result[i].sums;
                }
                that.ord_sum ="￥" + sum ;

              }else{
                //that.$message.warning(res.message);
              }
            }),
            //顾客地区分布统计
            getAction("machineShop/index/get2",{}).then((res)=>{
              if(res.success){
                console.log(res)
                for (let i = 0; i <res.result.length ; i++) {
                  pieData.push({
                    item:res.result[i].province,
                    count:res.result[i].nums
                  })
                }
              }else{
                //that.$message.warning(res.message);
              }
            }),
            //订单状态统计
            getAction("machineShop/index/get3",{}).then((res)=>{
              if(res.success){
                console.log(res)
                var sum = 0;
                var tuikuan_status = 0;
                var fau_status_sum = 0;
                for (let i = 0; i <res.result.length ; i++) {
                  sum +=res.result[i].nums;
                  tuikuan_status = res.result[3].nums/sum;
                  fau_status_sum =(Math.round(tuikuan_status*10000))/100+'%';//小数转换百分比
                  that.ord_tuikuan =fau_status_sum;
                }
                console.log(sum);
                console.log(tuikuan_status);
                console.log(fau_status_sum);
              }else{
                //that.$message.warning(res.message);
              }
            }),
            //故障信息统计
            getAction("machineShop/index/get4",{}).then((res)=>{
              if(res.success){
                console.log(res)
                var sum = 0;
                for (let i = 0; i <res.result.length ; i++) {
                  sum +=res.result[i].nums;
                }
                that.fau_sum = sum ;


                for (let i = 0; i <res.result.length ; i++) {
                  areaData.push({
                    x:res.result[i].mm +"月",
                    y:res.result[i].nums
                  });
                };

              }else{
                //that.$message.warning(res.message);
              }
            })
            ,
            //员工签到状态统计
            getAction("machineShop/index/get5",{}).then((res)=>{
              if(res.success){
                console.log(res)
                console.log("这个是员工签到状态统计数据")
                for (let i = 0; i <res.result.length ; i++) {


                  line_data.push({
                    //empMm/empSignin/empNosign/empLeave/empAbsent
                      type:res.result[i].empMm + '月',
                      value: res.result[i].empSignin + '人'
                  })
                  // console.log(value);
                }
                for (let i = 0; i <res.result.length ; i++) {
                  line_data2.push({
                    //empMm/empSignin/empNosign/empLeave/empAbsent
                    type:res.result[i].empMm + '月',
                    value: res.result[i].empNosign + '人'
                  })
                  // console.log(value);
                }
                for (let i = 0; i <res.result.length ; i++) {
                  line_data3.push({
                    //empMm/empSignin/empNosign/empLeave/empAbsent
                    type:res.result[i].empMm + '月',
                    value: res.result[i].empLeave + '人'
                  })
                  // console.log(value);
                }
                for (let i = 0; i <res.result.length ; i++) {
                  line_data4.push({
                    //empMm/empSignin/empNosign/empLeave/empAbsent
                    type:res.result[i].empMm + '月',
                    value: res.result[i].empAbsent + '人'
                  })
                  // console.log(value);
                }
              }else{
                //that.$message.warning(res.message);
              }
            })
      },
    },
  }

</script>

<style lang="less" scoped>
  .circle-cust{
    position: relative;
    top: 28px;
    left: -100%;
  }
  .extra-wrapper {
    line-height: 55px;
    padding-right: 24px;

    .extra-item {
      display: inline-block;
      margin-right: 24px;

      a {
        margin-left: 24px;
      }
    }
  }

  /* 首页访问量统计 */
  .head-info {
    position: relative;
    text-align: left;
    padding: 0 32px 0 0;
    min-width: 125px;

    &.center {
      text-align: center;
      padding: 0 32px;
    }

    span {
      color: rgba(0, 0, 0, .45);
      display: inline-block;
      font-size: .95rem;
      line-height: 42px;
      margin-bottom: 4px;
    }
    p {
      line-height: 42px;
      margin: 0;
      a {
        font-weight: 600;
        font-size: 1rem;
      }
    }
  }
</style>